package com.zz.ai.controller;

import jakarta.annotation.Resource;
import org.apache.poi.hssf.record.common.FtrHeader;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class ChatAPI {

    @Resource
    private ChatClient moonshotChatClient;

    @Resource
    private Init init;

    @GetMapping("ai/chat")
    public String chat(@RequestParam(value = "message") String message){
        return moonshotChatClient.prompt().functions("getHotelAddress","doHotelUpdateArticle").user(message).call().content();
    }

    @GetMapping("ai/clear")
    public String clear(){
        try {
            Thread.sleep(10l);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        init.chatMemory.clear("default");

        return "对话已经清空";
    }

    @GetMapping("ai/func")
    public String func(ChatAPI chatAPI, @RequestParam(value = "message") String message){
        return moonshotChatClient.prompt(message)
                .functions("askForLeave","payLimitForAsk","getHotelAddress")
                .call().content();
    }



}
